/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ircclient;
import javax.swing.JTextArea;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.BoxLayout;
import java.net.Socket;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.io.PrintWriter;

/**
 *
 * @author Justin
 */
public class Gui implements ActionListener {
    private JFrame window;
    private JTextArea chat;
    private JScrollPane scroller;
    private JPanel ori;
    private JButton button;
    private JTextField inputArea;
    private SendChat send;
    public Gui(String name, Socket s)
    {
        try
        {
            send = new SendChat(new PrintWriter(s.getOutputStream()),name);
        }
        catch(Exception e){}
        inputArea=new JTextField(20);
        button = new JButton("enter");
        ori=new JPanel();
        ori.setLayout(new BoxLayout(ori, BoxLayout.PAGE_AXIS));
        window=new JFrame("IRC");
        window.setSize(500,720);
        window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        chat = new JTextArea(40,40);
        chat.setEditable(false);
        scroller=new JScrollPane(chat);
        scroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        ori.add(scroller);
        ori.add(inputArea);
        ori.add(button);
        window.add(ori);
        window.setVisible(true);
        button.addActionListener(this);
    }
    public void addToChat(String s)
    {
        chat.append(s+'\n');
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        send.sendToServer(inputArea.getText());
        inputArea.setText("");
    }
    
}
